#ifndef __CLASSOBJECTPOOL_H__
#define __CLASSOBJECTPOOL_H__

#include "Any.h"
#include <string>
#include <functional>
#include <memory>
#include <unordered_map>
#include <mutex>
#include <iostream>
#include <atomic>
#include <boost/utility.hpp>

using namespace std;

class ClassObjectPool: boost::noncopyable {

public:

    ClassObjectPool()
    {}

    void Insert(const std::string objectName, Any object);

    template<typename T>
    shared_ptr<T> Get(const std::string objectName) {
        lock_guard<mutex> lock(m_mutex);
        if(!m_object_map.count(objectName)) {
            throw logic_error("NOT FIND objectName");
        }
        Any objectAny = m_object_map[objectName];
        return objectAny.AnyCast<shared_ptr<T>>();
    }

    bool Erase(const std::string objectName);

    ~ClassObjectPool() {
    }

private:
    static std::unordered_map<string, Any> m_object_map;
    static std::mutex m_mutex;
};

#endif
